package com.cuit.mimall.controller.frontend;

import com.cuit.mimall.entity.ShoppingCart;
import com.cuit.mimall.entity.User;
import com.cuit.mimall.service.IShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author TeaWu
 * @folder 前台/购物车
 * @since 2023-07-04
 */
@RestController("frontendShoppingCartController")
@RequestMapping("/shopping-cart")
public class ShoppingCartController {
    private final IShoppingCartService shoppingCartService;

    @Autowired
    public ShoppingCartController(IShoppingCartService shoppingCartService) {
        this.shoppingCartService = shoppingCartService;
    }

    @RequestMapping("/addCart")
    @ResponseBody
    public String addCart(String callback, ShoppingCart shoppingCart, User user) {
        int result = shoppingCartService.addCart(shoppingCart, user);
        return callback == null ? result + "" : callback + "('" + result + "')";
    }
}
